package com.example.springboottools.test.pic;

import java.sql.*;

public class DBUtil {
    private static Connection conn = null;
    private static ResultSet rs = null;
    private static PreparedStatement ste =null;
    private final static String URL = "jdbc:oracle:thin:@10.10.5.225:1521:TSCD";
    private final static String USERNAME = "staples";
    private final static String PASSWORD = "staples2323W";
 /*   private final static String URL = "jdbc:oracle:thin:@10.10.5.225:1521:TSCD";//test环境
    private final static String USERNAME = "staples";
    private final static String PASSWORD = "staples2323W";*/


    static{
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }//加载就注册驱动
    }



    //获取connection连接对象的方法；
    public  Connection getCon(){
        try {
            conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return conn;
    }
    public static   Connection getConnection(){
        try {
            conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return conn;
    }


    //关闭资源的方法
    public void closeIO() {
        try {
            if (rs != null) {
                rs.close();
            }
            if (ste != null) {
                ste.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public static void close(Connection conn) {
        try {
            if (rs != null) {
                rs.close();
            }
            if (ste != null) {
                ste.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public static void close( ) {
        try {
            if (rs != null) {
                rs.close();
            }
            if (ste != null) {
                ste.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
